package com.um.jdy.app.user.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.um.jdy.app.user.entity.dto.*;
import com.um.jdy.app.user.entity.vo.LoginVO;
import com.um.jdy.app.user.manager.LoginManager;
import com.um.jdy.app.user.manager.UserManager;
import com.um.jdy.common.member.entity.vo.MemberUserVO;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "用户")
@RestController
@RequestMapping("/api/v1/user")
@SaCheckLogin
@Validated
public class UserController {

    @Autowired
    UserManager userManager;

    @ApiOperation("查询用户信息")
    @GetMapping()
    public Response<MemberUserVO> get(){
        return Response.success(userManager.get());
    }

    @ApiOperation("修改用户信息")
    @PutMapping()
    public Response edit(@RequestBody @Valid EditUserParam param){
        userManager.edit(param);
        return Response.success();
    }

    @ApiOperation("退出登陆")
    @PostMapping("signout")
    public Response signout(){
        StpUtil.logout();
        return Response.success();
    }


}
